package lastRites.game.terrain;

import lastRites.entities.Player;
import lastRites.enums.BlockType;
import lastRites.enums.TileSetName;
import lastRites.game.LastRites;
import lastRites.game.interfaces.Rendering;

import org.newdawn.slick.Color;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.StateBasedGame;

public class TerrainBlock implements Rendering {
	private String		tileImageName;
	private TileSetName	tileSetName;
	private BlockType	blockType;
	private int			row, col, x, y, width, height;

	public TerrainBlock() {};

	public TerrainBlock(TileSetName tileSet, BlockType blockType, int row, int col) {
		super();
		this.tileSetName = tileSet;
		this.blockType = blockType;
		this.row = row;
		this.col = col;
		this.x = col * LastRites.BLOCK_SIZE;
		this.y = row * LastRites.BLOCK_SIZE;
		this.width = LastRites.TILE_MAP.get( tileSetName ).get( blockType ) == null ? LastRites.BLOCK_SIZE : LastRites.TILE_MAP.get( tileSetName ).get( blockType ).getWidth();
		this.height = LastRites.TILE_MAP.get( tileSetName ).get( blockType ) == null ? LastRites.BLOCK_SIZE : LastRites.TILE_MAP.get( tileSetName ).get( blockType ).getHeight();
	}

	@Override
	public void render(GameContainer container, StateBasedGame game, Graphics g) throws SlickException {
		if( blockType == BlockType.AIR ) { return; }
		LastRites.TILE_MAP.get( tileSetName ).get( blockType ).draw( x, y - ( height - LastRites.BLOCK_SIZE ) );
		g.setColor( Color.red );
		g.drawRect( x, y, 16, 16 );
		g.setColor( Color.white );
	}

	public boolean isFarmable() {
		return false;
	}

	public void harvest(Player player, float f) {}

	public int getRow() {
		return row;
	}

	public void setRow(int row) {
		this.row = row;
	}

	public int getCol() {
		return col;
	}

	public void setCol(int col) {
		this.col = col;
	}

	public int getX() {
		return x;
	}

	public void setX(int x) {
		this.x = x;
	}

	public int getY() {
		return y;
	}

	public void setY(int y) {
		this.y = y;
	}

	public int getWidth() {
		return width;
	}

	public void setWidth(int width) {
		this.width = width;
	}

	public int getHeight() {
		return height;
	}

	public void setHeight(int height) {
		this.height = height;
	}

	public String getTileImageName() {
		return tileImageName;
	}

	public void setTileImageName(String tileImageName) {
		this.tileImageName = tileImageName;
	}

	public TileSetName getTileSetName() {
		return tileSetName;
	}

	public void setTileSetName(TileSetName tileSetName) {
		this.tileSetName = tileSetName;
	}

	public BlockType getBlockType() {
		return blockType;
	}

	public void setBlockType(BlockType blockType) {
		this.blockType = blockType;
	}
}
